from django.db import models


class TiebaNote(models.Model):
    note_id = models.CharField(max_length=644, verbose_name='帖子ID', unique=True)
    title = models.CharField(max_length=255, verbose_name='帖子标题')
    desc = models.TextField(null=True, blank=True, verbose_name='帖子描述')
    note_url = models.CharField(max_length=255, verbose_name='帖子链接')
    publish_time = models.CharField(max_length=255, verbose_name='发布时间')
    user_link = models.CharField(max_length=255, default='', verbose_name='用户主页链接')
    user_nickname = models.CharField(max_length=255, default='', verbose_name='用户昵称')
    user_avatar = models.CharField(max_length=255, default='', verbose_name='用户头像地址')
    tieba_id = models.CharField(max_length=255, default='', verbose_name='贴吧ID', null=True, blank=True)
    tieba_name = models.CharField(max_length=255, verbose_name='贴吧名称', null=True, blank=True)
    tieba_link = models.CharField(max_length=255, verbose_name='贴吧链接', null=True, blank=True)
    total_replay_num = models.IntegerField(default=0, verbose_name='帖子回复总数')
    total_replay_page = models.IntegerField(default=0, verbose_name='帖子回复总页数')
    ip_location = models.CharField(max_length=255, default='', verbose_name='IP地理位置')
    add_ts = models.BigIntegerField(verbose_name='添加时间戳')
    last_modify_ts = models.BigIntegerField(verbose_name='最后修改时间戳')
    source_keyword = models.CharField(max_length=255, default='', verbose_name='搜索来源关键字')
    task_id = models.CharField(max_length=255, verbose_name='任务ID', null=True, blank=True)
    class Meta:
        db_table = 'tieba_note'
        verbose_name = '贴吧帖子表'
        indexes = [
            models.Index(fields=['note_id'], name='idx_tieba_note_note_id'),
            models.Index(fields=['publish_time'], name='idx_tieba_note_publish_time'),
        ]


class TiebaComment(models.Model):
    comment_id = models.CharField(max_length=255, verbose_name='评论ID')
    parent_comment_id = models.CharField(max_length=255, default='', verbose_name='父评论ID')
    content = models.TextField(verbose_name='评论内容')
    user_link = models.CharField(max_length=255, default='', verbose_name='用户主页链接')
    user_nickname = models.CharField(max_length=255, default='', verbose_name='用户昵称')
    user_avatar = models.CharField(max_length=255, default='', verbose_name='用户头像地址')
    tieba_id = models.CharField(max_length=255, default='', verbose_name='贴吧ID', null=True, blank=True)
    tieba_name = models.CharField(max_length=255, verbose_name='贴吧名称', null=True, blank=True)
    tieba_link = models.CharField(max_length=255, verbose_name='贴吧链接', null=True, blank=True)
    publish_time = models.CharField(max_length=255, default='', verbose_name='发布时间')
    ip_location = models.CharField(max_length=255, default='', verbose_name='IP地理位置')
    sub_comment_count = models.IntegerField(default=0, verbose_name='子评论数')
    note_id = models.ForeignKey(
        TiebaNote,
        to_field='note_id',
        db_column='note_id',
        on_delete=models.CASCADE,
        related_name='comments',
        verbose_name='帖子关联',
        null=True,
        blank=True,
    )
    note_url = models.CharField(max_length=255, verbose_name='帖子链接')
    add_ts = models.BigIntegerField(verbose_name='添加时间戳')
    last_modify_ts = models.BigIntegerField(verbose_name='最后修改时间戳')

    class Meta:
        db_table = 'tieba_comment'
        verbose_name = '贴吧评论表'
        indexes = [
            models.Index(fields=['comment_id'], name='idx_tieba_comment_comment_id'),
            models.Index(fields=['note_id'], name='idx_tieba_comment_note_id'),
            models.Index(fields=['publish_time'], name='idx_tieba_comment_publish_time'),
        ]


class TiebaCreator(models.Model):
    user_id = models.CharField(max_length=64, verbose_name='用户ID')
    user_name = models.CharField(max_length=64, verbose_name='用户名')
    nickname = models.CharField(max_length=64, null=True, blank=True, verbose_name='用户昵称')
    avatar = models.CharField(max_length=255, null=True, blank=True, verbose_name='用户头像地址')
    ip_location = models.CharField(max_length=255, null=True, blank=True, verbose_name='评论时的IP地址')
    add_ts = models.BigIntegerField(verbose_name='记录添加时间戳')
    last_modify_ts = models.BigIntegerField(verbose_name='记录最后修改时间戳')
    gender = models.CharField(max_length=2, null=True, blank=True, verbose_name='性别')
    follows = models.CharField(max_length=16, null=True, blank=True, verbose_name='关注数')
    fans = models.CharField(max_length=16, null=True, blank=True, verbose_name='粉丝数')
    registration_duration = models.CharField(max_length=16, null=True, blank=True, verbose_name='吧龄')
    task_id = models.CharField(max_length=255, verbose_name='任务ID', null=True, blank=True)
    class Meta:
        db_table = 'tieba_creator'
        verbose_name = '贴吧创作者'
